/**
 * 
 */
package com.jm.web.tags;


import com.jm.utils.StringHelper;
import com.jm.web.builder.PageTitleBuilder;
import com.jm.web.form.PageTitle;
import com.jm.web.tags.support.BaseTag;

/**
 * @author yanjie
 *
 * 2011/9/29 上午8:53:53
 */
public class PageTitleTag extends BaseTag{
	private static final long serialVersionUID = 8812593837325463794L;
	protected PageTitle pageTitle = null;
	
	@Override
	protected void preStartTag() {
		super.preStartTag();
		this.pageTitle = this.getPage().getPageTitle();
	}
	
	@Override
	protected int onStartTag() {
		if(this.pageTitle != null && !this.pageTitle.isEnab()){
			return SKIP_BODY;
		}
		
		if(this.getPage().isExport() && !this.isEp()){
			this.pageTitle.setEnab(false);
			return SKIP_BODY;
		}
		return EVAL_BODY_BUFFERED;
	}
	
	@Override
	public String getBuilderName() {
		return PageTitleBuilder.class.getName();
	}
	
	@Override
	public int onAfterBody() {
		//设置页面标题
		if(this.getBodyContent() != null)
			this.pageTitle.setTitle(StringHelper.getValue(this.getBodyContent().getString()).trim());
		return super.onAfterBody();
	}
	
	@Override
	public void clear() {
		super.clear();
		this.pageTitle = null;
	}

	public PageTitle getPageTitle() {
		return pageTitle;
	}

	public void setPageTitle(PageTitle pageTitle) {
		this.pageTitle = pageTitle;
	}
}
